package service

import (
	"blog/doc/test"
	"blog/utils"
	"blog/utils/tools"
	"fmt"
	"os"
	"time"
)

func HelloKitty() {

}

// 各种的小工具

// ChangeFileNamesByDir 通过文件夹批量修改文件名称
func ChangeFileNamesByDir() {
	filePath := "F:\\熊安\\学习教程\\老男孩Go语言（基础+进阶+就业）"
	//filePath = "D:\\data\\tmp_file"
	list, err := tools.GetAllFile(filePath)
	if err != nil {
		return
	}
	for _, v := range list {
		// 修改文件名称
		newFileName := utils.RemovePrefix(v, "【樱花论坛 www.sakuraaaa.com】")
		err = os.Rename(filePath+"\\"+v, filePath+"\\"+newFileName)
		if err != nil {
			fmt.Println(err)
			continue
		}
	}
	fmt.Println("修改成功")
}

// ReadPathTxtToEs 读取目录下所有的txt文件，将内容导入到es中
// filePath := "D:\\code\\python2\\data\\账号\\books"
// 需要开启es初始化连接
func ReadPathTxtToEs(filePath string) {
	files, err := tools.GetAllFile(filePath)
	if err != nil {
		return
	}
	for _, v := range files {
		// 获取字符串结尾4个字符
		end := v[len(v)-4:]
		//fmt.Println(end)
		if end == ".txt" {
			fmt.Println("执行", filePath+"\\"+v)
			go test.TxtToEs(filePath + "\\" + v)
		}
		time.Sleep(time.Second * 2)
	}
	time.Sleep(time.Second * 100)
}
